import { app } from "@/config/env";
import { deepMerge, getBrowser } from "cl-admin/utils";
import store from "store";
const browser = getBrowser();
export default {
	state: {
		info: {
			...app
		},
		browser: {
			...browser,
			isMobile: false
		},
		collapse: browser.isMini ? true : false,
		// 是否全屏
		isFullscreen: false
	},
	getters: {
		// 应用配置
		app: state => state.info,
		// 配置信息
		conf: state => state.info.conf,
		// 浏览器信息
		browser: state => state.browser,
		// 左侧菜单是否收起
		menuCollapse: state => state.collapse,
		// 是否开启了页面全屏
		isFullscreen: state => state.isFullscreen
	},
	actions: {
		appLoad({ getters, dispatch }) {
			if (getters.token) {
				// 读取菜单权限
				dispatch("permMenu");
				// 获取用户信息
				// dispatch("userInfo");
			}
		},
		setFullscreen({ commit, state }, val) {
			commit("SET_FULLSCREEN", val);
		}
	},
	mutations: {
		// 设置浏览器信息
		SET_BROWSER(state) {
			state.browser = getBrowser();
		},

		// 收起左侧菜单
		COLLAPSE_MENU(state, val = false) {
			state.collapse = val;
		},

		// 更新应用配置
		UPDATE_APP(state, val) {
			deepMerge(state.info, val);
			store.set("__app__", state.info);
		},

		// 设置全屏
		SET_FULLSCREEN(state, val) {
			state.isFullscreen = val;
		}
	}
};
